home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / source_code / dhtmlunl / dhtml.exe / CD Content / Chap08 / dun8_7.txt < prev    next >
Encoding:
Text File  |  1997-12-18  |  2.1 KB  |  58 lines

  1. <html>
  2.  
  3. <head>
  4.  
  5. <title>Doorway</title>
  6.  
  7. </head>
  8.  
  9. <script language="JavaScript">
  10.  
  11. <!---//
  12.  
  13. //first set up a global variable to hold the result returned by
  14.  
  15. //the whichVersion() function
  16.  
  17. var b = whichVersion()
  18.  
  19. //the standard whichVersion function
  20.  
  21. function whichVersion() {
  22.  
  23.    var myBrowser = navigator.userAgent;
  24.  
  25.    if((myBrowser.lastIndexOf("MSIE") != -1) &&
  26.  
  27.      (myBrowser.lastIndexOf("4.0") != -1)) return "IE4"
  28.  
  29.    if((myBrowser.lastIndexOf("MSIE") != -1) &&
  30.  
  31.      (myBrowser.lastIndexOf("3.0") != -1)) return "IE3"
  32.  
  33.    if((myBrowser.lastIndexOf("2.0") != -1) return "NS2"
  34.  
  35.    if((myBrowser.lastIndexOf("3.0") != -1) &&
  36.  
  37.      (myBrowser.lastIndexOf("MSIE") == -1)) return "NS3"
  38.  
  39.    if((myBrowser.lastIndexOf("4.0") != -1) &&
  40.  
  41.      (myBrowser.lastIndexOf("MSIE") == -1)) return "NS4"
  42.  
  43. }
  44.  
  45. //this version of the  routeMe() function changes the current
  46.  
  47. //window's location to Netscape's page.
  48.  
  49. function routeMe() {
  50.  
  51.     var exitMsg = ''; //a placeholder for the exit message
  52.  
  53.     var exitURL = ''; //a placeholder for the exit URL
  54.  
  55.     //first check to see if "NS"is in the string b
  56.  
  57.     //which we assigned the result of whichVersion to
  58.  
  59.     if (b.lastIndexOf("NS" != -1)){
  60.  
  61.        exitURL = "http://www.netscape.com/";
  62.  
  63.     } else {
  64.  
  65.        exitURL = "http://www.microsoft.com/";
  66.  
  67.     }
  68.  
  69.     //now it's just simple string matching to check the
  70.  
  71.     //version and assign an exit message to the user
  72.  
  73.     if (b == "NS3") { exitMsg = 'Netscape 3.0? Upgrade to 4.0!'; }
  74.  
  75.     if (b == "NS2") { exitMsg = 'Netscape 2.0? Upgrade to 4.0!'; }
  76.  
  77.     if (b == "IE3") { exitMsg = 'Internet Explorer 3?  Try 4.0!'; }
  78.  
  79.     //one of my favorite tricks.  If the exitMsg variable
  80.  
  81.     //is not blank, then perform some action.  In this case
  82.  
  83.     //it's to alert the user to a possible upgrade
  84.  
  85.     if (exitMsg != '') {
  86.  
  87.        alert('An Upgrade Is Available!\n' + exitMsg);
  88.  
  89.     }
  90.  
  91.     self.location = exitURL;
  92.  
  93. }
  94.  
  95. //--->
  96.  
  97. </script>
  98.  
  99. <body bgcolor="#ffffff">
  100.  
  101. <center>
  102.  
  103. <form>
  104.  
  105. <input type="button" onClick="routeMe()" value="Go Home!">
  106.  
  107. </form>
  108.  
  109. </center>
  110.  
  111. </body>
  112.  
  113. </html>
  114.  
  115.